#include "configuration.h"

#include <iostream>

namespace po = boost::program_options;

int main(int argc, char** argv) {

    auto keys_description = get_keys();

    try {
        po::variables_map options;

        po::store(po::parse_command_line(argc, argv, keys_description), options);
        po::notify(options);

        if (options.count("help")) {
            std::cout << "\n" << keys_description << std::endl; 
            return 0;
        }

        std::map<std::string, std::string> variables;
        std::map<std::string, std::string> formats;
        try {
            SettingsType settings = get_settings(get_config_file_name(options));
            variables = settings.first, formats = settings.second;    
        } catch(std::exception& e) {
            std::cerr << e.what() << "\n";
            std::cerr << "Using default settings." << std::endl;
        }
         
        if (!options.count("root")) {
            throw std::invalid_argument("Root directory is not specified.");
        }

        auto file_dedupe = get_file_dedupe(options, variables, formats);
        file_dedupe->process();

    } catch (std::exception &e) {
        std::cerr << e.what() << std::endl;
        std::cerr << std::endl << keys_description << std::endl;
        return 1;
    }
    return 0;
}
